<template>
	<view 
		class="coupon-item"
		:class="{ disabled: coupon.status === 'disabled' }"
	>
		<view class="coupon-left" :style="{ background: getGradientColor(coupon.category) }">
			<view class="coupon-amount">
				<text class="currency" v-if="typeof coupon.amount === 'number'">¥</text>
				<text class="amount">{{ coupon.amount }}</text>
			</view>
			<view class="coupon-condition" v-if="coupon.condition > 0">
				满{{ coupon.condition }}可用
			</view>
			<view class="coupon-condition" v-else>
				无门槛使用
			</view>
		</view>
		
		<view class="coupon-center">
			<view class="coupon-title">{{ coupon.title }}</view>
			<view class="coupon-desc">{{ coupon.description }}</view>
			<view class="coupon-time">
				<uni-icons type="calendar" size="12" color="#999"></uni-icons>
				<text>{{ coupon.validTime }}</text>
			</view>
		</view>
		
		<view class="coupon-right">
			<button 
				class="receive-btn"
				:class="{ 
					received: coupon.status === 'received',
					disabled: coupon.status === 'disabled'
				}"
				@click="handleReceive"
				:disabled="coupon.status !== 'available'"
			>
				{{ getButtonText(coupon.status) }}
			</button>
		</view>
	</view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
	coupon: {
		type: Object,
		required: true
	}
})

const emit = defineEmits(['receive'])

const getGradientColor = (category) => {
	const colors = {
		discount: 'linear-gradient(135deg, #ff6b6b, #ff8e8e)',
		percentage: 'linear-gradient(135deg, #4ecdc4, #44a08d)',
		shipping: 'linear-gradient(135deg, #45b7d1, #96c93d)',
		newuser: 'linear-gradient(135deg, #f093fb, #f5576c)',
		vip: 'linear-gradient(135deg, #ffecd2, #fcb69f)',
		default: 'linear-gradient(135deg, #667eea, #764ba2)'
	}
	return colors[category] || colors.default
}

const getButtonText = (status) => {
	switch (status) {
		case 'available':
			return '立即领取'
		case 'received':
			return '已领取'
		case 'disabled':
			return '已过期'
		default:
			return '立即领取'
	}
}

const handleReceive = () => {
	if (props.coupon.status === 'available') {
		emit('receive', props.coupon)
	}
}
</script>

<style lang="scss" scoped>
.coupon-item {
	display: flex;
	background: #fff;
	border-radius: 20rpx;
	margin-bottom: 20rpx;
	overflow: hidden;
	box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
	
	&.disabled {
		opacity: 0.6;
	}
}

.coupon-left {
	width: 200rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	color: #fff;
	position: relative;
	
	&::after {
		content: '';
		position: absolute;
		right: -10rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 20rpx;
		height: 20rpx;
		background: #f5f5f5;
		border-radius: 50%;
	}
	
	.coupon-amount {
		display: flex;
		align-items: baseline;
		
		.currency {
			font-size: 24rpx;
		}
		
		.amount {
			font-size: 48rpx;
			font-weight: bold;
		}
	}
	
	.coupon-condition {
		font-size: 20rpx;
		margin-top: 10rpx;
		opacity: 0.9;
	}
}

.coupon-center {
	flex: 1;
	padding: 30rpx;
	
	.coupon-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10rpx;
	}
	
	.coupon-desc {
		font-size: 24rpx;
		color: #666;
		margin-bottom: 20rpx;
	}
	
	.coupon-time {
		display: flex;
		align-items: center;
		font-size: 22rpx;
		color: #999;
		
		text {
			margin-left: 8rpx;
		}
	}
}

.coupon-right {
	width: 160rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 30rpx 20rpx;
	
	.receive-btn {
		width: 120rpx;
		height: 60rpx;
		line-height: 60rpx;
		background: $uni-color-primary;
		color: #fff;
		border: none;
		border-radius: 30rpx;
		font-size: 24rpx;
		
		&.received {
			background: #ccc;
			color: #999;
		}
		
		&.disabled {
			background: #f0f0f0;
			color: #ccc;
		}
	}
}
</style> 